package org.xuyuji.study.spring_jdbctemplate_demo.service;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.xuyuji.study.spring_jdbctemplate_demo.dao.IUserDao;
import org.xuyuji.study.spring_jdbctemplate_demo.model.UserModel;

@Service("trade")
public class TradeService {
	private static final Logger logger = Logger.getLogger(TradeService.class);
	
	@Autowired
	private IUserDao userDao;
	
	@Transactional
	public void trade(UserModel seller, UserModel buyer, long price){
		logger.info("交易开始");
		userDao.modify(seller.setMoney(seller.getMoney() + price));
		userDao.modify(buyer.setMoney(buyer.getMoney() - price));
		logger.info("交易结束");
	}
}
